package cn.com.yang.thread;
/**
 * @Desc<...>
 * @Author 杨亿金
 * @Date 2020/12/14 17:17
 * @CopyRight
 * @Version
 */
public class DeadThread {
    /**
     * 线程死循环
     */
    public static void creatBusyThread(){
        Thread thread = new Thread(new Runnable() {
            @Override
            public void run() {
                while (true){
                    ;//耗尽系统分配给它的执行时间，直到线程切换为止
                }
            }
        },"BustThread");
        thread.start();
    }

    /**
     * 线程锁等待
     * @param lock
     */
    public static void creatLockThread(final Object lock){
        Thread thread = new Thread(new Runnable() {
            @Override
            public void run() {
                synchronized(lock){
                    try {
                        lock.wait();//等待notify()或者notifyAll() 线程处于WAITING
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        });
    }
}
